%section scalarvis

% colormapping alpha scaling

The \texttt{Smoke} visualizer in our application can be used for \emph{scalar visualization}. Formally, a scalar dataset represents a function 
\begin{equation}
  f : \mathcal{D} \rightarrow  \mathbb{R}.
\end{equation}
Scalar visualization attempts to visually convey the relation between sampled
points $p_i \in \mathcal{D}$ and sampled values $f_i \in \mathbb{R}$.  The most
widespread visualization method for scalar data is \textit{color mapping}
\cite{scivisbookch05}. This method and the way it is implemented in our
visualization will be treated in the following subsection.

\subsection{Color Mapping}
\label{subsec:colormapping}
For every point in the domain of interest $\mathcal{D}$, a colormap should
apply a function $s$ which maps the scalar value $s$ in that point to a color.
The two most common methods of achieving such a map are color look-up tables
and transfer functions \cite{scivisbookch05}. In our implementation, only color
look-up tables are used. Formally, such a table can be understood as a uniform
sampling of the color mapping function $c$ \cite{scivisbookch05}:
\begin{equation}
  C = \{c_i\}_{i = 1,\ldots,N},
\end{equation}
where
\begin{equation}
  c_i = c \left(\frac{(N - i)f_{\mathrm{min}} + i f_{\mathrm{max}}}{N}\right).
\end{equation}
and $N$ is number of distinct colors in the colormap. In our implementation, a
class \texttt{Colormap} has a vector of length $N$ containing
\texttt{Color}s serving as a look up table.  

\subsection{Effective Colormaps}
Ideally, the actual colors to which values are mapped have some relation to the
visualized data. When visualizing temperature, having low temperatures
correspond to bluish colors and high temperatures to reddish ones will be
intuitive. When visualizing the scan of a skull, having white colors correspond
with areas where bone is present and black colors with areas where bone is
absent will allow for easy understanding of the visualization. We dubbed one of
our original colormaps \textit{Ocean}: it linearly interpolates from black for
low values to a dark blue, to teal and finally white for high values. This
colormap's effectivity stems from our intuitive estimate of the depth of a
large volume of water. The cover of this report shows the \texttt{Visualizer}
\texttt{Smoke} using this colormap. Since one of our datasets contains circular
data (angle data), we also design a colormap whose maximal value equals its
minimal value. Figure \ref{fig:circular} shows \texttt{Smoke} using this
colormap to visualize angle data.

\begin{figure}[ht]
  \begin{center}
    \includegraphics[trim=2mm 2mm 0mm 2mm,clip,width=\textwidth]{./images/angle_smoke_glyph_v}
  \end{center}
  \caption{Using a circular colormap. \texttt{Smoke} visualizes of
    the angle of the fluid velocity vectorfield. \texttt{Glyphs} drawn for the
    same vector field show how angles correspond to colors. Note that this visualization makes it easy to identify regions where the direction of the vector field changes dramatically, like vortices and saddle points.}
  \label{fig:circular}
\end{figure}


\subsection{Implementation}
We provide easy means for programmers to define new colormaps. Given a set of
colors defined as HSV-triplets\footnote{HSV: Hue, Saturation, Value} a vector
containing the map from intensity level intervals to colors is automatically
generated, linearly interpolating through all the colors. Defining the colors
in HSV has at least two advantages:
\begin{itemize}
  \item The HSV space is more intuitive for humans than the RGB space.  
  \item When defining the map in HSV space, it is easy to see whether all the
    colors have the same H, S or V value. If all colors have one or more
    dimensions  in common, the colormap can be adjusted by setting that
    dimension to a certain value. This allows for interactive refinement of the
    colormap. 
\end{itemize}
The value $s$ can be mapped to a color vector index by using either automatic
scaling or clamping. Both are described in the following subsection.

\subsection{Scaling}
Two scaling methods are implemented. In \textit{automatic scaling}, scalar
values $s$ are mapped to values $i$ in the range $(0,N)$  using the following
function:
\begin{equation}
  i =  N\left( \frac{s - \mathrm{min}_\mathrm{data}}{\mathrm{max}_\mathrm{data} -
  \mathrm{min}_\mathrm{data}}\right)
\end{equation}
where $\mathrm{max}_\mathrm{data}$ and $\mathrm{min}_\mathrm{data}$ are the
maximum and minimum values of the dataset which the colormap is currently
visualizing. Flooring this value $i$ (and taking care of the exceptional case
$i = N$) will directly yield an index into the vector containing the colors.

Automatic scaling has the obvious advantage that the colormap is able to
display all the scalar values $s$ in the dataset. However, there are at least
two disadvantages:

\begin{itemize}
  \item When the distribution of scalar values $s$ is not uniform -- e.g. a few
    points have high values while a lot of points have lower values -- the
    colormap might not be able to to visualize the interesting regions of the
    dataset in a way that convey the phenomena that occur there.
  \item When the extrema of the dataset change in time, the mapping will also
    change. That means that a visualization of a certain timestep will be hard
    to compare with the visualization of another timestep.
\end{itemize}
To circumvent these problems, one could instead use \textit{clamping}. Then,
scalar values are mapped to values $i$ in the following way:
\begin{equation}
  i =  N\left( \frac{s - \mathrm{min}_\mathrm{clamp}}{\mathrm{max}_\mathrm{clamp} -
  \mathrm{min}_\mathrm{clamp}}\right)
\end{equation}
where $\mathrm{max}_\mathrm{clamp}$ and $\mathrm{min}_\mathrm{clamp}$ are
values set by the user. Flooring this value $i$, and setting it to 0 if $i < 0$
and to $N-1$ if $i > N-1$ directly yields the color vector index.

By adjusting the values $\mathrm{max}_\mathrm{clamp}$ and
$\mathrm{min}_\mathrm{clamp}$, the user can interactively find interesting
regions of the dataset. 
